﻿using System;
using Xunit;

namespace Unity.String.Tests.Number
{
    public class InternalSpanExtendTest
    {
        [Fact]
        public void EqualsOrdinalIgnoreCaseTest()
        {
            ReadOnlySpan<char> testEmptySpan = new ReadOnlySpan<char>();
            Assert.True(testEmptySpan.EqualsOrdinalIgnoreCase(testEmptySpan));
            
            ReadOnlySpan<char> testSourceSpan = new ReadOnlySpan<char>("Hello, world!".ToCharArray());
            ReadOnlySpan<char> testCompareSpan = new ReadOnlySpan<char>("hello, world!".ToCharArray());
            Assert.True(testSourceSpan.EqualsOrdinalIgnoreCase(testCompareSpan));
            
            ReadOnlySpan<char> testNotEqualSpan = new ReadOnlySpan<char>("Press any key to continue".ToCharArray());
            Assert.False(testSourceSpan.EqualsOrdinalIgnoreCase(testNotEqualSpan));
            
            ReadOnlySpan<char> testNotAsciiSpan = new ReadOnlySpan<char>("Нажмите любую кнопку для продолжения".ToCharArray());
            Assert.True(testNotAsciiSpan.EqualsOrdinalIgnoreCase(testNotAsciiSpan));

            ReadOnlySpan<char> testUnicodeSpan = new ReadOnlySpan<char>("😂😁😜 😭🤦😱".ToCharArray());
            Assert.True(testUnicodeSpan.EqualsOrdinalIgnoreCase(testUnicodeSpan));
            
            Assert.False(testSourceSpan.EqualsOrdinalIgnoreCase(testUnicodeSpan));

            ReadOnlySpan<char> testOneSymbolSpan = new ReadOnlySpan<char>("a".ToCharArray());
            Assert.True(testOneSymbolSpan.EqualsOrdinalIgnoreCase(testOneSymbolSpan));
            
            ReadOnlySpan<char> testOneSymbolNonAsciiSpan = new ReadOnlySpan<char>("Я".ToCharArray());
            Assert.True(testOneSymbolNonAsciiSpan.EqualsOrdinalIgnoreCase(testOneSymbolNonAsciiSpan));
            
            Assert.False(testOneSymbolSpan.EqualsOrdinalIgnoreCase(testOneSymbolNonAsciiSpan));
            
            ReadOnlySpan<char> testThreeSymbolSpan = new ReadOnlySpan<char>("abc".ToCharArray());
            Assert.True(testThreeSymbolSpan.EqualsOrdinalIgnoreCase(testThreeSymbolSpan));
            
            ReadOnlySpan<char> testThreeSymbolNonAsciiSpan = new ReadOnlySpan<char>("эюя".ToCharArray());
            Assert.True(testThreeSymbolNonAsciiSpan.EqualsOrdinalIgnoreCase(testThreeSymbolNonAsciiSpan));
            
            ReadOnlySpan<char> testThreeSymbolWithUnicodeSpan = new ReadOnlySpan<char>("😜 ".ToCharArray());
            Assert.True(testThreeSymbolWithUnicodeSpan.EqualsOrdinalIgnoreCase(testThreeSymbolWithUnicodeSpan));
            
            Assert.False(testThreeSymbolSpan.EqualsOrdinalIgnoreCase(testThreeSymbolWithUnicodeSpan));
        }

        [Fact]
        public void AllCharsInUInt32AreAsciiTest()
        {
            uint testValue = 123;
            Assert.True(InternalSpanExtend.AllCharsInUInt32AreAscii(testValue));
        }
        
        [Fact]
        public void AllCharsInUInt64AreAsciiTest()
        {
            ulong testValue = 123L;
            Assert.True(InternalSpanExtend.AllCharsInUInt64AreAscii(testValue));
        }

        [Fact]
        public void UInt32OrdinalIgnoreCaseAsciiTest()
        {
            uint testAValue = 123u;
            uint testBValue = 012u;
            Assert.False(InternalSpanExtend.UInt32OrdinalIgnoreCaseAscii(testAValue, testBValue));
            uint testCValue = 123u;
            Assert.True(InternalSpanExtend.UInt32OrdinalIgnoreCaseAscii(testAValue, testCValue));
        }

        [Fact]
        public void UInt64OrdinalIgnoreCaseAsciiTest()
        {
            ulong testAValue = 123ul;
            ulong testBValue = 012ul;
            Assert.False(InternalSpanExtend.UInt64OrdinalIgnoreCaseAscii(testAValue, testBValue));
            ulong testCValue = 123ul;
            Assert.True(InternalSpanExtend.UInt64OrdinalIgnoreCaseAscii(testAValue, testCValue));
        }
    }
}